import Vue from "vue";
import VueRouter from "vue-router";
//废弃
import Submit from "@/components/Submit";
//正式路由
const Find = () => import(/* webpackChunkName: "findModule" */ "../pages/find");
const Error = () =>
  import(/* webpackChunkName: "errorModule" */ "@/components/Error");
const SearchRes = () =>
  import(/* webpackChunkName: "commonModule" */ "../pages/searchRes");
const Copy = () =>
  import(/* webpackChunkName: "commonModule" */ "@/components/Copy");
const Sidebar = () =>
  import(/* webpackChunkName: "commonModule" */ "@/components/Sidebar");
const Footer = () =>
  import(/* webpackChunkName: "commonModule" */ "@/components/Footer");
const Header = () =>
  import(/* webpackChunkName: "commonModule" */ "@/components/Header");
const Tag = () => import(/* webpackChunkName: "tagModule" */ "../pages/tag");
const FavorTag = () =>
  import(/* webpackChunkName: "tagModule" */ "../pages/favorTag");
const UploadBg = () =>
  import(/* webpackChunkName: "personModule" */ "@/components/UploadBg");
const UploadImg = () =>
  import(/* webpackChunkName: "personModule" */ "@/components/UploadImg");
const Person = () =>
  import(/* webpackChunkName: "personModule" */ "../pages/person");
const Collect = () =>
  import(/* webpackChunkName: "inforModule" */ "../pages/collect");
const Share = () =>
  import(/* webpackChunkName: "inforModule" */ "../pages/share");
const Comment = () =>
  import(/* webpackChunkName: "inforModule" */ "../pages/comment");
const Infor = () =>
  import(/* webpackChunkName: "inforModule" */ "../pages/infor");
const Request = () =>
  import(/* webpackChunkName: "requestModule" */ "../pages/request");
const IdCheck = () =>
  import(/* webpackChunkName: "requestModule" */ "../pages/idCheck");
const Paydetail = () =>
  import(/* webpackChunkName: "giftModule" */ "@/components/Paydetail");
const Paymodal = () =>
  import(/* webpackChunkName: "giftModule" */ "@/components/Paymodal");
const GiftModal = () =>
  import(/* webpackChunkName: "giftModule" */ "@/components/GiftModal");
const Gift = () => import(/* webpackChunkName: "giftModule" */ "../pages/gift");
const Drafts = () =>
  import(/* webpackChunkName: "articleModule" */ "../pages/drafts");
const Black = () =>
  import(/* webpackChunkName: "articleModule" */ "../pages/black");
const ArtDetail = () =>
  import(/* webpackChunkName: "articleModule" */ "../pages/artDetail");
const Home = () => import(/* webpackChunkName: "UpModule" */ "../pages/home");
const Fans = () => import(/* webpackChunkName: "UpModule" */ "../pages/fans");
const Question = () =>
  import(/* webpackChunkName: "loginModule" */ "@/components/Question");
const FinishInfor = () =>
  import(/* webpackChunkName: "loginModule" */ "@/components/FinishInfor");
const Login = () =>
  import(/* webpackChunkName: "loginModule" */ "../pages/login");
const Talk = () =>
  import(/* webpackChunkName: "editorModule" */ "@/components/Talk");
const Editor = () =>
  import(/* webpackChunkName: "editorModule" */ "../pages/editor");
const Sign = () =>
  import(/* webpackChunkName: "indexPage" */ "@/components/Sign");
const ForwardModal = () =>
  import(/* webpackChunkName: "indexPage" */ "@/components/ForwardModal");
const Index = () =>
  import(/* webpackChunkName: "indexPage" */ "../pages/index");
const InterestTag = () =>
  import(/* webpackChunkName: "indexPage" */ "@/components/InterestTag");
const ConcernTag = () =>
  import(/* webpackChunkName: "indexPage" */ "@/components/ConcernTag");
const PersonModal = () =>
  import(/* webpackChunkName: "indexPage" */ "@/components/PersonModal");
const Idea = () => import(/* webpackChunkName: "idea" */ "../pages/idea");
const Report = () =>
  import(/* webpackChunkName: "report" */ "@/components/Report");
const Code = () => import(/* webpackChunkName: "code" */ "@/components/Code");
const Phone = () => import(/* webpackChunkName: "phone" */ "../pages/phone");
const Contenteditable = () =>
  import(/* webpackChunkName: "editor" */ "@/components/Contenteditable");
const Activity = () =>
  import(/* webpackChunkName: "editor" */ "../pages/activity");
const AgreeDetail = () =>
  import(/* webpackChunkName: "agree" */ "../pages/agreeDetail");
const Hot = () => import(/* webpackChunkName: "hot" */ "../pages/hot");

const Geet = () => import(/* webpackChunkName: "geet" */ "@/components/Geet");
const SelectTag = () => import(/* webpackChunkName: "geet" */ "@/components/SelectTag");
const Shieldmodal = () => import(/* webpackChunkName: "Shieldmodal" */ "@/components/Shieldmodal");
const Shield = ()=>import(/* webpackChunkName: "shield" */ "../pages/shield");
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "login",
    component: Login,
    meta: {
      title: "来闻-登录页",
    },
  },
  {
    path: "/",
    name: "find",
    component: Find,
    meta: {
      keepAlive: true, //是否缓存
      // title:'来闻-发现页'
      isBack:false,//是否返回
      title: "来闻-laismell-大家快来闻闻看",
    },
  },
  {
    path: "/index",
    name: "index",
    component: Index,
    meta: {
      isLogin: true,
      title: "来闻-主页",
      keepAlive: true,
      isBack:false,//是否返回
    },
 
  },
  {
    path: "/header",
    name: "header",
    component: Header,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/Geet",
    name: "Geet",
    component: Geet,
  },
  {
    path: "/footer",
    name: "footer",
    component: Footer,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/Shieldmodal",
    name: "Shieldmodal",
    component: Shieldmodal,
  },
  {
    path: "/Sidebar",
    name: "Sidebar",
    component: Sidebar,
  },
  {
    path: "/Submit",
    name: "Submit",
    component: Submit,
  },

  {
    path: "/artDetail",
    name: "artDetail",
    component: ArtDetail,
    meta: {
      title: "来闻-文章详情页",
    },
  },
  {
    path: "/hot",
    name: "hot",
    component: Hot,
    meta: {
      title: "来闻-热门页",
    },
  },
  {
    path: "/shield",
    name: "Shield",
    component: Shield,
    meta: {
      title: "来闻-屏蔽页",
    },
  },
  
  {
    path: "/agreeDetail",
    name: "agreeDetail",
    component: AgreeDetail,
    meta: {
      title: "来闻-协议详情页",
    },
  },
  {
    path: "/sign",
    name: "sign",
    component: Sign,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/person",
    name: "person",
    component: Person,
    meta: {
      isLogin: true,
      title: "来闻-个人信息修改页",
    },
  },
  {
    path: "/tag",
    name: "tag",
    component: Tag,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/infor",
    name: "infor",
    component: Infor,
    meta: {
      isLogin: true,
      title: "来闻-消息页",
    },
  },
  {
    path: "/request",
    name: "request",
    component: Request,
    meta: {
      isLogin: true,
      title: "来闻-认证页",
    },
  },
  {
    path: "/gift",
    name: "gift",
    meta: {
      isLogin: true,
      title: "来闻-礼物页",
    },
    component: Gift,
  },
  {
    path: "/Paymodal",
    name: "Paymodal",
    component: Paymodal,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/Paydetail",
    name: "Paydetail",
    component: Paydetail,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/UploadBg",
    name: "UploadBg",
    component: UploadBg,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/idCheck",
    name: "idCheck",
    component: IdCheck,
    meta: {
      isLogin: true,
      title: "来闻-认证详情页",
    },
  },
  {
    path: "/home",
    name: "home",
    component: Home,
  },
  {
    path: "/UploadImg",
    name: "UploadImg",
    component: UploadImg,
    meta: {
      isLogin: true,
      title: "来闻-用户页",
    },
  },

  {
    path: "/comment",
    name: "comment",
    component: Comment,
    meta: {
      isLogin: true,
      title: "来闻-评论页",
    },
  },
  {
    path: "/share",
    name: "share",
    component: Share,
    meta: {
      isLogin: true,
      title: "来闻-转发页",
    },
  },
  {
    path: "/collect",
    name: "collect",
    component: Collect,
    meta: {
      isLogin: true,
      title: "来闻-收藏页",
    },
  },
  {
    path: "/black",
    name: "black",
    component: Black,
    meta: {
      isLogin: true,
      title: "来闻-小黑屋",
    },
  },
  {
    path: "/drafts",
    name: "drafts",
    component: Drafts,
    meta: {
      isLogin: true,
      title: "来闻-草稿箱",
    },
  },
  {
    path: "/editor",
    name: "editor",
    component: Editor,
    meta: {
      isLogin: true,
      title: "来闻-编辑页",
    },
  },
  {
    path: "/Talk",
    name: "Talk",
    component: Talk,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/fans",
    name: "fans",
    component: Fans,
    meta: {
      isLogin: true,
      title: "来闻-用户详情页",
    },
  },
  {
    path: "/Question",
    name: "Question",
    component: Question,
    // meta: {
    //   isLogin: true,
    // },
  },
  {
    path: "/GiftModal",
    name: "GiftModal",
    component: GiftModal,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/PersonModal",
    name: "PersonModal",
    component: PersonModal,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/ForwardModal",
    name: "ForwardModal",
    component: ForwardModal,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/searchRes",
    name: "searchRes",
    component: SearchRes,
    meta: {
      isLogin: true,
      title: "来闻-搜索结果",
    },
  },
  {
    path: "/Copy",
    name: "Copy",
    component: Copy,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/SelectTag",
    name: "SelectTag",
    component: SelectTag,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/ConcernTag",
    name: "ConcernTag",
    component: ConcernTag,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/favorTag",
    name: "favorTag",
    component: FavorTag,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/FinishInfor",
    name: "FinishInfor",
    component: FinishInfor,
    meta: {
      // isLogin: true,
    },
  },
  {
    path: "/InterestTag",
    name: "InterestTag",
    component: InterestTag,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/idea",
    name: "idea",
    component: Idea,
    meta: {
      isLogin: true,
      title: "来闻-意见反馈",
    },
  },
  {
    path: "/Report",
    name: "Report",
    component: Report,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/Contenteditable",
    name: "Contenteditable",
    component: Contenteditable,
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/phone",
    name: "Phone",
    component: Phone,
    meta: {
      title: "来闻-登录页",
    },
  },
  {
    path: "/Code",
    name: "Code",
    component: Code,
    meta: {
      isLogin: true,
      title: "404",
    },
  },
  {
    path: "/activity",
    name: "activity",
    component: Activity,
    meta: {
      isLogin: true,
      title: "来闻-活动页",
    },
  },

  {
    path: "*",
    component: Error,
  },
];

const router = new VueRouter({
  // mode: "history",
  routes,
});
// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.matched.some((res) => res.meta.isLogin)) {
    //判断是否需要登录
    if (localStorage["token"]) {
      next();
    } else {
      next({
        path: "/",
      });
    }
  } else {
    next();
  }
  // 清空无用的页面缓存
  let toDepth = to.path.split("/").length;
  let fromDepth = from.path.split("/").length;
  if (toDepth < fromDepth) {
    from.meta.keepAlive = false;
    to.meta.keepAlive = true;
  }
});
export default router;
